package StackAndQuene;



import java.util.Arrays;

public class PersonalStack {//栈
    private int[] stack;
    private int top = -1;//顶部，好像不需要底部

    public PersonalStack(int length){
        this.stack = new int[length];
    }
    public Boolean push(int insert){//入栈
        if(top==this.stack.length-1){
            System.out.println("the stack is full");
            return false;
        }
        System.out.println("pushed element is:"+insert);
        this.stack[++this.top] = insert;
        return true;
    }
    public Boolean is_empty(){//判断是否为空
        if (top==-1){
            return true;
        }
        return false;
    }

    public Integer pop(){
        if (top==-1){
            System.out.println("the stack is empty");
            return null;
        }
        Integer temp = this.stack[top];
        this.top--;
        System.out.println("the poped element is:"+temp);
        return temp;
    }

    public void ToString(){
        System.out.println(Arrays.toString(this.stack));
    }

    public Integer peek(){
        return this.stack[this.top];
    }
}



